//
//  LWLoginCtrl.m
//  laowu
//
//  Created by 尹桥印 on 15/4/29.
//  Copyright (c) 2015年 长沙市岳麓区立早网络科技有限公司. All rights reserved.
//

#import "LWLoginCtrl.h"
#import "LWRegisterOneCtrl.h"
#import "LWForgotPwdCtrl.h"
#import "LWForgotPwdCtrl.h"

@interface LWLoginCtrl ()
- (IBAction)forgetPwdBtnClick:(id)sender;

@end

@implementation LWLoginCtrl

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setTitle:@"登录"];
    
    self.navigationItem.leftBarButtonItem = [UIBarButtonItem backItemWithTarget:self action:@selector(back)];
    
    [self.userNameView setCornerRadius:5 borderWidth:1 borderColor:HEXColor(@"#dfdfdf")];
    [self.pwdVeiw setCornerRadius:5 borderWidth:1 borderColor:HEXColor(@"#dfdfdf")];
}

-(void)back{
    [self dismissViewControllerAnimated:YES completion:nil];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"toHomeCtrl" object:nil];
}

- (IBAction)registerBtnClick:(id)sender {
    //注册
    LWRegisterOneCtrl *ctrl = [[LWRegisterOneCtrl alloc] init];
    [self.navigationController pushViewController:ctrl animated:YES];
}

- (IBAction)forgetBtnClick:(id)sender {
    //忘记密码
    LWForgotPwdCtrl *ctrl = [[LWForgotPwdCtrl alloc] init];
    [self.navigationController pushViewController:ctrl animated:YES];
}

- (IBAction)loginBtnClick:(id)sender {
    //登录
    if (ISBLANK(self.userNameField.text)) {
        [DialogUtils showTipsWithView:nil String:@"请输入手机号码或者身份证号码"];
        return;
    }
    if (ISBLANK(self.pwdField.text)) {
        [DialogUtils showTipsWithView:nil String:@"请输入密码"];
        return;
    }
    
    [MeDataTool loginWithUserName:self.userNameField.text password:self.pwdField.text success:^(LoginRes *result) {
        if (result.isSucc) {
            [DialogUtils showTipsWithView:nil String:@"登录成功"];
            //保存登录返回的东西
            [result.datas saveResult];
            [(AppDelegate *)[UIApplication sharedApplication].delegate pushBind];
            [self dismissViewControllerAnimated:YES completion:nil];
        }else{
            [DialogUtils showTipsWithView:nil String:result.msg];
        }
    } failure:^(NSError *error) {
        [DialogUtils showTipsWithView:nil String:@"登录失败"];
    }];
    
}
- (IBAction)forgetPwdBtnClick:(id)sender {
    LWForgotPwdCtrl *ctrl = [[LWForgotPwdCtrl alloc] init];
    [self.navigationController pushViewController:ctrl animated:YES];
}
@end
